﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Business_Object;
using Models;

namespace BusinessService.Account
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["btnRegister"] != null)
            {
                String UserName = Request["UserName"];
                String Password = Request["Password"];
                String Email = Request["Email"];
                String Address = Request["Address"];
                String Country = Request["Country"];
                String NumberPhone = Request["NumberPhone"];

               
                if(ValidateObject(UserName) && ValidateObject(Password) && ValidateObject(Email))
                {
                    TaiKhoan taiKhoan = new TaiKhoan();
                    taiKhoan.MaTaiKhoan = -1;
                    taiKhoan.TenDangNhap = UserName;
                    taiKhoan.MatKhau = Password;
                    taiKhoan.Email = Email;
                    taiKhoan.DiaChi = Address;
                    taiKhoan.QuocGia = Country;
                    taiKhoan.DienThoai = NumberPhone;
                    CustomMembershipProvider membershipProvider = new CustomMembershipProvider();
                    membershipProvider.CreateUser(taiKhoan);
                    if (taiKhoan.MaTaiKhoan != -1)
                    {
                        Response.Redirect("Logins.aspx");
                    }
                }
              

            }

        }
        private bool ValidateObject(String name)
        {
            if(String.IsNullOrEmpty(name) || name =="")
                return false;
            
            return true;
        }
    }
}
